<?php



include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/tuijian/inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/qq/inc.php");
$g_cgival = array();
$g_pro = array();
//$_GET["db_debug"]=1;
$g_show = array();

function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;

	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	cgi::both($g_cgival["id"], "id", "");
	$g_cgival["id"] = string::un_html($g_cgival["id"]);
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = string::un_html($g_cgival["uid"]);
	
	cgi::both($g_cgival["type"], "type", "add");
	$g_cgival["type"] = string::un_html($g_cgival["type"]);
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	$id = $g_cgival["id"];
	$uid = $g_cgival["uid"];
	if(!$id)
	{
		throw new Exception("id不能为空！");
	}
	$admin_uid = admin::admin_get_login_uid();
	
	
	$db_tuijian_daren = new db_tuijian_daren();
	
	$user_info = new user_info();
	
	
	if($g_cgival["type"] == "add")
	{
		$item = $user_info->get_user_info_by_uid($id);
		$site_id = $item["main_topic_id"];
		$db_tuijian_daren->admin_insert_tuijian_daren($id,$order,serialize($item),$admin_uid,$site_id);
		
	}
	elseif($g_cgival["type"] == "edit")
	{
		$item = $user_info->get_user_info_by_uid($uid);
		$site_id = $item["main_topic_id"];
		if(!$item)
		{
			throw new Exception("用户信息不存在！");
		}
		$db_tuijian_daren->admin_update_by_id($id,$status="",$uid,$order,serialize($item),$admin_uid,$site_id);
		
	}
	elseif($g_cgival["type"] == "undel")
	{
		$db_tuijian_daren->admin_update_by_uid($id,1);
		
	}
	

}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
	{
		print_r($g_show);
		exit;
	}
	
	
	echo json_encode($g_show);
}

